package com.by.controller;

import cn.hutool.core.bean.BeanUtil;
import com.by.bean.ProductParame;
import com.by.bean.ResultBean;
import com.by.group.V;
import com.by.mapper.ProductParameMapper;
import com.by.query.ProductParameQuery;
import com.by.query.ProductParameSave;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author :LYJ
 * @version : 1.0
 * @date : 2025/3/1 10:31
 * @desc : 产品参数表
 * @since : JDK17
 */
@RestController
@Api(tags = "产品参数")
@RequestMapping("/api")
public class ProductParameController extends BaseController {
    @Autowired
    ProductParameMapper productParameMapper;

    @PostMapping("/productParame/list")
    @ApiOperation("查询列表")
    public ResultBean queryByMap(@Validated ProductParame productParame, BindingResult result) {
        V.validate(result);
        return success("success", productParameMapper.queryByMap(BeanUtil.beanToMap(productParame)));
    }

    @ApiOperation("多条件查询")
    @PostMapping("/productParame/query")
    public ResultBean queryByInfo(@RequestBody @Validated ProductParameQuery productParameQuery, BindingResult result) {
        V.validate(result);
        List<ProductParame> productParames = productParameMapper.queryByInfo(productParameQuery);
        return success("success", productParames);
    }

    @ApiOperation("保存一张或多张图片到数据库中")
    @PostMapping("/productParame/savePic")
    public ResultBean saveParamePicture(@RequestBody @Validated ProductParameSave productParameSave, BindingResult result) {
        V.validate(result);
        return success("success", productParameMapper.saveParamePicture(productParameSave));
    }
}
